package com.JinYuan.ex;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;

/**
 * @author 金园
 * @create 2022/5/10
 * @Description
 * @className MyHandlerExcepion
 * @packageName com.JinYuan.ex
 */
@Component
public class MyHandlerException implements HandlerExceptionResolver {
    //HandlerExceptionResolver：异常处理器：监听前端控制器，捕获前端控制器抛出的异常
    /*
    

     */
    @Override
    //处理异常的方法
    public ModelAndView resolveException(
            HttpServletRequest httpServletRequest,
            HttpServletResponse httpServletResponse,
            Object o,
            Exception e) {
        
        ModelAndView mav = new ModelAndView();
        //打印堆栈信息
        e.printStackTrace();
        mav.addObject("msg","未知错误，请及时联系管理员");
        //指定视图页面
        mav.setViewName("/error.jsp");
        return mav;
    }
}
